"use strict";

exports.__esModule = true;
exports.default = clearColumnItem;
var C = _interopRequireWildcard(require("../../../i18n/constants"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const KEY = exports.KEY = 'clear_column';

/**
 * @returns {object}
 */
function clearColumnItem() {
  return {
    key: KEY,
    name() {
      return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_CLEAR_COLUMN);
    },
    callback(key, selection) {
      const startColumn = selection[0].start.col;
      const endColumn = selection[0].end.col;
      if (this.countRows()) {
        this.populateFromArray(0, startColumn, [[null]], Math.max(selection[0].start.row, selection[0].end.row), endColumn, 'ContextMenu.clearColumn');
      }
    },
    disabled() {
      const range = this.getSelectedRangeActive();
      if (!range || range.isSingleHeader() && range.highlight.col < 0 || !this.selection.isSelectedByColumnHeader()) {
        return true;
      }
      let atLeastOneNonReadOnly = false;
      range.forAll((row, col) => {
        if (row < 0 || col < 0) {
          return true;
        }
        const {
          readOnly
        } = this.getCellMeta(row, col);
        if (!readOnly) {
          atLeastOneNonReadOnly = true;
          return false;
        }
        return true;
      });
      return !atLeastOneNonReadOnly;
    }
  };
}